﻿/*
Autor...: Ivan M. Kruger
Empresa.: Home Kruger
Data....: 03/03/2011
*/

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
using ik.ExtensionMethor;
//using ik.Enum;

namespace ik.Functions
{
    using System.Windows.Forms;
    using IWshRuntimeLibrary; //namespace windows script host object model
    using System.Runtime.InteropServices;

    #region "enum"
    public enum enRegister
    {
        Register = 0,
        Unregister = 1
    }
    public enum enEncryption
    {
        Encriptar = 0,
        Descriptar = 1
    }
    #endregion

    #region "WMI sample"
    //add reference system.management
    //using System.Management;

    //public static String whoisLoggedIn(String HostOrIP)
    //{
    //    System.Management.ConnectionOptions myConnectionOptions = new System.Management.ConnectionOptions();
    //    myConnectionOptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;

    //    System.Management.ManagementScope objwmiservice;
    //    System.Management.ManagementObjectSearcher myObjectSearcher;
    //    System.Management.ManagementObjectCollection myCollection;

    //    try
    //    {
    //        objwmiservice = new System.Management.ManagementScope(("\\\\" + (HostOrIP + "\\root\\cimv2")), myConnectionOptions);
    //        objwmiservice.Connect();
    //        myObjectSearcher = new System.Management.ManagementObjectSearcher(objwmiservice.Path.ToString(), "Select UserName from Win32_ComputerSystem");
    //        myObjectSearcher.Options.Timeout = new TimeSpan(0, 0, 0, 0, 7000);
    //        myCollection = myObjectSearcher.Get();

    //        foreach (System.Management.ManagementObject myObject in myCollection)
    //        {
    //            if (!(myObject.GetPropertyValue("Username") == null))
    //            {
    //                string Userx = myObject.GetPropertyValue("Username").ToString();
    //                int posx = Userx.LastIndexOf("\\");
    //                if ((posx > 0))
    //                {
    //                    Userx = Userx.Substring((posx + 1));
    //                    return Userx.ToUpper();
    //                }
    //            }
    //        }
    //        return "<Nobody>";
    //    }
    //    catch (Exception)
    //    {
    //        return "<Nobody>";
    //    }
    //}
    #endregion

    /// <summary>
    /// funções gerais do sistema
    /// </summary>
    public class clFunctions
    {

        #region "CreateDataTable -> DataTable"
        /// <summary>
        /// cria um DataTable
        /// </summary>
        /// <param name="colName">params: coluna, type</param>
        /// <example>DataTable _dt = cd.CreateDataTable("id", typeof(Int32), "Nome", typeof(String));</example>
        /// <returns>DataTable</returns>
        public DataTable CreateDataTable(params Object[] colName)
        {
            try
            {
                DataTable _dt = new DataTable();
                for (int i = 0; i < colName.Length; i = i + 2)
                    _dt.Columns.Add(new DataColumn(colName[i].ToString(), (Type)colName[i + 1]));
                return _dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "AddRowDataTable -> void"
        /// <summary>
        /// adiciona nova linha em um DataTable
        /// </summary>
        /// <param name="dt">nome do DataTable</param>
        /// <param name="col_val">Coluna, valor</param>
        public void AddRowDataTable(DataTable dt, params Object[] col_val)
        {
            try
            {
                DataRow r = dt.NewRow();
                for (int i = 0; i < col_val.Length; i = i + 2)
                    r[col_val[i].ToString()] = col_val[i + 1];
                dt.Rows.Add(r);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "CrypTo -> Criptografia de string"
        /// <summary>
        /// Criptografia e descriptografia de string
        /// </summary>
        /// <param name="text">Texto a ser encriptado</param>
        /// <param name="crypt">True-Encrypt; False-Decrypt</param>
        /// <returns>Retorna string encriptada/decriptada</returns>
        /// <example>Crypto("Texto", True)</example>
        public String CrypTo(String text, enEncryption crypt)
        {
            try
            {
                if (crypt == enEncryption.Encriptar)
                    return Convert.ToBase64String(Encoding.ASCII.GetBytes(text));
                else
                    return Encoding.ASCII.GetString(Convert.FromBase64String(text));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static String CrypTo2(String text, enEncryption crypt)
        {
            try
            {
                return new clFunctions().CrypTo(text, crypt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "MD5Hash-> encripta"
        /// <summary>
        /// cria hash com MD5
        /// </summary>
        /// <param name="text">texto para criar o hash MD5</param>
        /// <returns>string hash</returns>
        public String MD5Hash(String text)
        {
            try
            {
                System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(text);
                byte[] hash = md5.ComputeHash(inputBytes);
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int i = 0; i < hash.Length; i++)
                    sb.Append(hash[i].ToString("X2"));
                return sb.ToString();
            }
            catch (Exception ex)
            { throw ex; }
        }
        #endregion

        #region "WriteEvent -> Grava evento no eventview do windows"
        /// <summary>
        /// Grava evento no event viewer do windows
        /// </summary>
        /// <param name="str">Texto a ser gravado no envet view</param>
        /// <param name="tipo">tipo da gravidade</param>
        //public void WriteEvent(String str, System.Diagnostics.EventLogEntryType tipo)
        //{
        //    try
        //    {
        //        if (!System.Diagnostics.EventLog.SourceExists(LogEventView, Environment.MachineName))
        //            try
        //            {
        //                System.Diagnostics.EventLog.CreateEventSource(LogEventView, LogEventView);
        //            }
        //            catch (Exception e)
        //            {
        //                new clTrataErros(e, "event viewer", 0, true, false, enDebugger.Não);
        //            }
        //        //System.Diagnostics.EventLog.DeleteEventSource(LogEventView, Environment.MachineName);
        //        System.Diagnostics.EventLog.WriteEntry(LogEventView, str, tipo, 1);
        //    }
        //    catch (System.ComponentModel.Win32Exception exFull)
        //    {
        //        try
        //        {
        //            System.Diagnostics.EventLog.Delete(LogEventView, Environment.MachineName);
        //        }
        //        catch (Exception)
        //        {
        //            throw exFull;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}
        #endregion

        #region "GetAppConfig, GetAppConfigConnectionStrings"
        /// <summary>
        /// le o arquivo app.config
        /// </summary>
        /// <param name="key">chave</param>
        /// <returns>String</returns>
        public String GetAppConfig(String key)
        {
            try
            {
                return System.Configuration.ConfigurationManager.AppSettings[key].ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// le o arquivo app.config
        /// </summary>
        /// <param name="key">chave</param>
        /// <param name="crypt">decripta informação</param>
        /// <returns>String</returns>
        public String GetAppConfig(String key, enEncryption crypt)
        {
            return CrypTo(System.Configuration.ConfigurationManager.AppSettings[key].ToString(), crypt);
        }

        public String GetAppConfigConnectionStrings(String key)
        {
            try
            {
                return System.Configuration.ConfigurationManager.ConnectionStrings[key].ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "WriteAppConfig -> Grava a nova configuração"
        public Boolean WriteAppConfig(String key, String valor)
        {
            try
            {
                System.Configuration.Configuration objConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
                System.Configuration.AppSettingsSection objAppSettings = (System.Configuration.AppSettingsSection)objConfig.GetSection(ik.Configuration.AppConfig.appSettings);
                if (objAppSettings != null)
                {
                    objAppSettings.Settings[key].Value = valor;

                    objConfig.Save(System.Configuration.ConfigurationSaveMode.Minimal);
                    System.Configuration.ConfigurationManager.RefreshSection(ik.Configuration.AppConfig.appSettings);
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "SendMail"
        /// <summary>
        /// envia e-mail para a lista parametrizada
        /// </summary>
        /// <param name="subject">assunto</param>
        /// <param name="body">mensagem</param>
        public void SendMail(String to, String subject, String body)
        {
            try
            {
                if (to == "") to = "ivan.kruger@salfer.com.br";
                System.Net.Mail.SmtpClient _smtp = new System.Net.Mail.SmtpClient("mail.salfer.com.br", 25);
                System.Net.Mail.MailMessage _msg = new System.Net.Mail.MailMessage("SQLServer@salfer.com.br", to, subject, body);
                System.Net.NetworkCredential _crd = new System.Net.NetworkCredential("SQLServer@salfer.com.br", "********");
                _smtp.Credentials = _crd;
                _smtp.Send(_msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "ArrayChange"
        /// <summary>
        /// redimensiona um arrray
        /// </summary>
        /// <param name="arr">array de strings</param>
        /// <returns>String[]</returns>
        public static String[] ArrayChange(String[] arr)
        {
            try
            {
                Array.Resize<String>(ref arr, arr.Length + 1);
                return arr;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// redimensiona um arrray
        /// </summary>
        /// <param name="arr">array de Objects</param>
        /// <returns>String[]</returns>
        public static Object[] ArrayChange(Object[] arr)
        {
            try
            {
                Array.Resize<Object>(ref arr, arr.Length + 1);
                return arr;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "Regsvr32_DllOcx"
        /// 
        //
        /// <summary>
        /// dll or ocx register
        /// </summary>
        /// <param name="ts">terminal server name</param>
        /// <param name="PathAndFile">full path and file</param>
        /// <param name="type">register ou unregister</param>
        /// <returns>Boolean</returns>
        public static Boolean Regsvr32_DllOcx(String ts, String PathAndFile, ik.Functions.enRegister type)
        {
            try
            {
                if (ik.Functions.enRegister.Unregister == type)
                    Execute_psexec(ts + @" regsvr32 /s /u " + @"""" + PathAndFile + @"""");
                else
                    Execute_psexec(ts + @" regsvr32 /s " + @"""" + PathAndFile + @"""");

                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "Execute_psexec"
        /// <summary>
        /// execute methor by PSEXEC
        /// </summary>
        /// <param name="arguments">arguments or parameters</param>
        /// <returns>String output psexec</returns>
        public static String Execute_psexec(String arguments)
        {
            try
            {
                System.Diagnostics.Process _p = new System.Diagnostics.Process();
                _p.StartInfo.FileName = System.IO.Path.Combine(Environment.CurrentDirectory, "psexec.exe");

                if (arguments != "")
                    _p.StartInfo.Arguments = arguments;

                _p.EnableRaisingEvents = false;
                _p.StartInfo.UseShellExecute = false;
                _p.StartInfo.RedirectStandardOutput = true;
                _p.StartInfo.CreateNoWindow = true;
                _p.Start();
                _p.WaitForExit();
                String _output = _p.StandardOutput.ReadToEnd();
                _p.WaitForExit();
                _p.Dispose();
                _p = null;

                return _output;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "ApplicationTimeWait"
        /// <summary>
        /// create a simple pause in the system and start a DoEvents()
        /// </summary>
        /// <param name="miliseconds">time in miliseconds</param>
        public static void ApplicationTimeWait(Int32 miliseconds)
        {
            try
            {
                System.Threading.Thread.Sleep(miliseconds);
                System.Windows.Forms.Application.DoEvents();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "GetFormat -> string"
        /// <summary>
        /// formata os campos de acordo com o TYPE
        /// </summary>
        /// <param name="obj">objeto com o valor para formatar</param>
        /// <returns>item formatado conforme GetType()</returns>
        public String GetFormat(object obj)
        {
            if (obj == null) return "null";

            String _return = ((object)obj).ToString();

            if (obj.GetType() == typeof(System.String))
                return "?" + _return.Replace("?", "_") + "?";

            else if (obj.GetType() == typeof(System.Decimal) || obj.GetType() == typeof(System.Single) || obj.GetType() == typeof(System.Double))
                return Decimal.Parse(_return).ToString().Replace(",", ".");

            else if (obj.GetType() == typeof(System.Int16))
                return Int16.Parse(_return).ToString();

            else if (obj.GetType() == typeof(System.Int32))
                return Int32.Parse(_return).ToString();

            else if (obj.GetType() == typeof(System.Int64))
                return Int64.Parse(_return).ToString();

            else if (obj.GetType() == typeof(System.Boolean))
                if ((Boolean)obj) return "1";
                else return "0";

            else if (obj.GetType() == typeof(System.DateTime))
                return "?" + ((DateTime)obj).ToString("yyyy-MM-dd HH:mm:ss") + "?";

            else if (obj.GetType() == typeof(System.DBNull))
                return "NULL";

            else
                return _return;
        }
        #endregion

        #region "InputBox"
        /// <summary>
        /// cria um InputBox 
        /// </summary>
        /// <param name="title">título</param>
        /// <param name="promptText">valor do prompt</param>
        /// <param name="value">valor default</param>
        /// <returns>DialogResult</returns>
        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new System.Drawing.Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new System.Drawing.Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }
        #endregion

        #region "CalculateStdDev -> Double"
        public Double CalculateStdDev(Double[] Values, DeviationType CalculationType)
        {
            Double SumOfValuesSquared = 0;
            Double SumOfValues = 0;
            try
            {
                foreach (Double item in Values)
                    SumOfValues += item;

                foreach (Double item in Values)
                    SumOfValuesSquared += Math.Pow(item, 2);

                if (CalculationType == DeviationType.Sample)
                    return Math.Sqrt((SumOfValuesSquared - Math.Pow(SumOfValues, 2) / Values.Length) / (Values.Length - 1));
                else
                    return Math.Sqrt((SumOfValuesSquared - Math.Pow(SumOfValues, 2) / Values.Length) / Values.Length);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public enum DeviationType
        {
            Population,
            Sample
        }
        #endregion

        #region "GetHostName"
        /// <summary>
        /// Get hostname
        /// </summary>
        public static String GetHostName()
        {
            // Get host name
            return System.Net.Dns.GetHostName();
        }
        #endregion

        #region "GetIpByHost"
        /// <summary>
        /// get list of IP by hostname
        /// </summary>
        /// <returns>String</returns>
        public static String GetIpByHostSingle()
        {
            try
            {
                return System.Net.Dns.GetHostEntry(GetHostName()).AddressList[0].ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// get list of IP by hostname
        /// </summary>
        /// <param name="host">host</param>
        /// <returns>String</returns>
        public static String GetIpByHostSingle(String host)
        {
            try
            {
                return System.Net.Dns.GetHostEntry(host).AddressList[0].ToString();
                //return System.Net.Dns.GetHostByName(host).AddressList[0].ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// get list of IP by hostname
        /// </summary>
        /// <param name="host">host</param>
        /// <returns>String[]</returns>
        public static String[] GetIpByHost(String host)
        {
            try
            {
                String[] _ip = new String[0];

                // Find host by name
                System.Net.IPHostEntry iphostentry = System.Net.Dns.GetHostEntry(host);
                //System.Net.IPHostEntry iphostentry = System.Net.Dns.GetHostByName(host);

                // Enumerate IP addresses
                foreach (System.Net.IPAddress ipaddress in iphostentry.AddressList)
                {
                    _ip = ik.Functions.clFunctions.ArrayChange(_ip);
                    _ip[_ip.Length - 1] = ipaddress.ToString();
                }
                return _ip;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

    }


    /// <summary>
    /// acesso ao WTS - windows terminal server
    /// </summary>
    public class WTS
    {
        #region "propriedades da classe"
        /// <summary>
        /// nome do terminal server
        /// </summary>
        public String TS { get; set; }
        /// <summary>
        /// nome da lista de retorno
        /// </summary>
        public List<ik.Functions.ListObjects.ListString3> ListaTS;
        #endregion

        #region "DllImport"
        [DllImport("wtsapi32.dll", SetLastError = true)]
        static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);

        [DllImport("kernel32.dll")]
        static extern int WTSGetActiveConsoleSessionId();

        [DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern IntPtr WTSOpenServer(string pServerName);
        #endregion

        #region "LogOffWTS"
        /// <summary>
        /// força o logoff em qualquer terminal
        /// </summary>
        /// <param name="session">id da sessão</param>
        /// <param name="wait">aguarda termino dos aplicativos</param>
        /// <returns>Boolean</returns>
        public Boolean LogOffWTS(Int32 session, Boolean wait)
        {
            try
            {
                if (TS == "")
                    throw new Exception("Não informado a propriedade TS");

                IntPtr ptr = WTSOpenServer(TS);
                return WTSLogoffSession(ptr, session, wait);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "getCurrentActiveConsoleSessionId"
        /// <summary>
        /// retorna o id da sessão corrente
        /// </summary>
        /// <returns>Int32</returns>
        public Int32 getCurrentActiveConsoleSessionId()
        {
            try
            {
                return WTSGetActiveConsoleSessionId();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "getListSessions"
        /// <summary>
        /// lista as sessões de um TS e grava em arquivo
        /// </summary>
        /// <param name="WriteFileTextCorrentAppPath">sobrecarga grava em arquivo</param>
        public void getListSessions(Boolean WriteFileTextCorrentAppPath)
        {
            try
            {
                if (TS == "")
                    throw new Exception("Não informado a propriedade TS");

                ik.FileSystem.clFileSystem _clfs = new ik.FileSystem.clFileSystem();
                List<ik.Functions.ListObjects.ListString3> _lst = new List<ik.Functions.ListObjects.ListString3>();
                getListSessions();
                _lst = ListaTS;
                TS += ".txt";
                _clfs.EraseFile(Environment.CurrentDirectory, TS);
                foreach (ik.Functions.ListObjects.ListString3 l in _lst)
                    _clfs.AppendFile(Environment.CurrentDirectory, TS, l.value1 + "|" + l.value2 + "|" + l.value3);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// lista de ik.Functions.ListObjects.ListString2 com as id conectadas
        /// </summary>
        public void getListSessions()
        {
            try
            {
                if (TS == "")
                    throw new Exception("Não informado a propriedade TS");

                ik.FileSystem.clFileSystem _clFS = new ik.FileSystem.clFileSystem();
                System.Diagnostics.Process _pro = new System.Diagnostics.Process();
                _pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                if (_clFS.ExistsFile(@"c:\windows\SysWOW64\query.exe"))
                    _pro.StartInfo.FileName = @"c:\windows\SysWOW64\query.exe";
                else
                    _pro.StartInfo.FileName = @"c:\windows\system32\query.exe";

                _pro.StartInfo.Arguments = "session /server:" + TS;
                _pro.EnableRaisingEvents = false;
                _pro.StartInfo.UseShellExecute = false;
                _pro.StartInfo.RedirectStandardOutput = true;
                _pro.StartInfo.CreateNoWindow = true;
                _pro.Start();
                String _output = _pro.StandardOutput.ReadToEnd();
                _pro.WaitForExit();
                _pro.Dispose();
                _pro = null;

                List<ik.Functions.ListObjects.ListString3> _lst = new List<ik.Functions.ListObjects.ListString3>();

                foreach (String s in _output.Replace("\r\n", "|").Split('|'))
                    if (s.Length > 50)
                        if (s.Substring(40, 7).isDecimal())
                            _lst.Add(new ik.Functions.ListObjects.ListString3(TS, s.Substring(40, 7).Trim(), s.Substring(19, 15).Trim()));
                ListaTS = _lst;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "getListStringSessions"
        ///<summary>
        ///lista de strings[] com as id conectadas
        ///</summary>
        ///<param name="machine">nome do terminal</param>
        ///<returns>String[]</returns>
        public String[] getListStringSessions(String machine)
        {
            try
            {
                getListSessions();
                List<ik.Functions.ListObjects.ListString3> _lst = ListaTS;

                String[] _clients = new String[0];
                foreach (ik.Functions.ListObjects.ListString3 l in _lst)
                {
                    _clients = ik.Functions.clFunctions.ArrayChange(_clients);
                    _clients[_clients.Length - 1] = l.value2;
                }

                return _clients;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }




    /// <summary>
    /// altera o link de um atalho
    /// </summary>
    public class ChangeLink
    {
        #region "sample to use"
        /*
            SAMPLE:
            try
            {
                ik.ChangeLink.ChangeLink _cl = new ik.ChangeLink.ChangeLink();

                System.IO.FileInfo _fi = _cl.getFileInfo(@"C:\Documents and Settings\All Users\Menu Iniciar",
                                                         @"Configurador de Loja.lnk");
                if (_fi != null)
                    _cl.ChangeLinkDestination(_fi, @"\\serverdes\Executaveis\2.42.00\ForaDoAr.exe");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            */
        #endregion

        #region "ChangeLinkDestination"
        /// <summary>
        /// altera o link do windows
        /// </summary>
        /// <param name="fileinfo">local do arquivo</param>
        /// <param name="fullTarget">caminho completo do novo destino</param>
        public void ChangeLinkDestination(FileInfo fileinfo, String fullTarget)
        {
            try
            {
                IWshShell _shell = new WshShell();
                IWshShortcut _lnk = _shell.CreateShortcut(fileinfo.FullName) as IWshShortcut;
                if (_lnk != null)
                {
                    _lnk.TargetPath = fullTarget;
                    _lnk.Save();
                }
                _lnk = null;
                _shell = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region "getFileInfo"
        /// <summary>
        /// retorna o FileInfo do link do windows
        /// </summary>
        /// <param name="folder">caminho do link</param>
        /// <param name="lnk">nome do linl</param>
        /// <returns>FileInfo</returns>
        public FileInfo getFileInfo(String folder, String lnk)
        {
            try
            {
                FileInfo[] _fis = new DirectoryInfo(folder).GetFiles(lnk);
                foreach (FileInfo _fi in _fis)
                {
                    if (_fi.Name.ToLower() == lnk.ToLower())
                        return _fi;
                }
                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }


    public static class ListObjects
    {
        #region "ListString 1 - 3"
        /// <summary>
        /// List String
        /// </summary>
        public partial class ListString
        {
            public String value { get; set; }
            public ListString() { }
            public ListString(String _value)
            {
                this.value = _value;
            }
        }

        /// <summary>
        /// List String two
        /// </summary>
        public partial class ListString2
        {
            public String value1 { get; set; }
            public String value2 { get; set; }
            public ListString2(String _value1, String _value2)
            {
                this.value1 = _value1;
                this.value2 = _value2;
            }
        }
        /// <summary>
        /// List String thre
        /// </summary>
        public partial class ListString3
        {
            public String value1 { get; set; }
            public String value2 { get; set; }
            public String value3 { get; set; }
            public ListString3(String _value1, String _value2, String _value3)
            {
                this.value1 = _value1;
                this.value2 = _value2;
                this.value3 = _value3;
            }
        }
        #endregion
    }
}


namespace ik.Configuration
{
    public sealed class AppConfig
    {
        public const String appSettings = "appSettings";
    }
}

/*
namespace ik.Zip2
{
    public class clZip
    {
            //// Path to directory of files to compress and decompress.
            //string dirpath = @"c:\users\public\reports";

            //DirectoryInfo di = new DirectoryInfo(dirpath);

            //// Compress the directory's files.
            //foreach (FileInfo fi in di.GetFiles())
            //    Compress(fi);

            //// Decompress all *.gz files in the directory.
            //foreach (FileInfo fi in di.GetFiles("*.gz"))
            //    Decompress(fi);

        /// <summary>
        /// compress file
        /// </summary>
        /// <param name="fi">file name</param>
        public void Compress(FileInfo fi)
        {
            // Get the stream of the source file.
            using (FileStream inFile = fi.OpenRead())
            {
                // Prevent compressing hidden and 
                // already compressed files.
                if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fi.Extension != ".gz")
                {
                    // Create the compressed file.
                    using (FileStream outFile = File.Create(fi.FullName + ".gz"))
                    {
                        using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
                        {
                            // Copy the source file into 
                            // the compression stream.
                            //inFile.CopyTo(Compress);
                            new FileInfo(fi.FullName).CopyTo(Compress.ToString());

                            Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                                fi.Name, fi.Length.ToString(), outFile.Length.ToString());
                        }
                    }
                }
            }
        }

        public void Decompress(FileInfo fi)
        {
            // Get the stream of the source file.
            using (FileStream inFile = fi.OpenRead())
            {
                // Get original file extension, for example
                // "doc" from report.doc.gz.
                string curFile = fi.FullName;
                string origName = curFile.Remove(curFile.Length -
                        fi.Extension.Length);

                //Create the decompressed file.
                using (FileStream outFile = File.Create(origName))
                {
                    using (GZipStream Decompress = new GZipStream(inFile,
                            CompressionMode.Decompress))
                    {
                        // Copy the decompression stream 
                        // into the output file.
                        //Decompress.CopyTo(outFile);

                        Console.WriteLine("Decompressed: {0}", fi.Name);

                    }
                }
            }
        }


    }
}
*/